<script src="<?= $url_styles ?>js/plugins/formselements/jquery.maskedinput-1.3.min.js"></script>
<script src="<?= $url_styles ?>js/plugins/formselements/ui.spinner.min.js"></script>
<script>
	$('.form-horizontal [name="start"]').datepicker();
	$('.form-horizontal [name="end"]').datepicker();
	$('.form-horizontal [name="start"]').datepicker('option','dateFormat','dd/mm/yy');
	$('.form-horizontal [name="end"]').datepicker('option','dateFormat','dd/mm/yy');
    var image_index=0;
	$('#add_image').live('click',function(){
        image_index++;
		$('#images').append('<div><input type="file" name="images_'+image_index+'" class="input-xlarges"/>\n\
							<a href="javascript:;" class="delete_image"><?=lang('delete')?></a></div>');
		return false;
	});
	$('.delete_image').live('click',function(){
		$(this).parent().fadeOut('fast',function(){$(this).remove()});
	});
	$('#tab4_check').click(function(){
		$('.form-horizontal [name="catalogues[]"]').attr('checked',this.checked);
	})
	$('#tab5_check').click(function(){
        $('.form-horizontal [name="locations[]"]').attr('checked',this.checked);
	})
    $('#tab4_check').click(function(){
        $('.form-horizontal [name="catalogues[]"]').attr('checked',this.checked);
    })
    $('#tab5_check').click(function(){
        $('.form-horizontal [name="locations[]"]').attr('checked',this.checked);
    })

     $(document).ready(function(){
		$('.form-horizontal').formParse({
			 data: <?= json_encode($product) ?>,
			 errors: <?= json_encode($errors)?>,
			 specialFields: ['info','locations','catalogues'],
		});
		 
        /*var product = <?= json_encode($product) ?>;
        $('.form-horizontal .product_image').attr('src',product.thumb);
        $('.form-horizontal .product_image').attr('style','max-width:120px;max-height:120px');
		for(var i in product){
			var e = $('.form-horizontal [name="'+i+'"]')
			switch(e.attr('type'))
			{
				case 'file':
					break;
				case 'checkbox':
					if(product[i]==1) e.attr('checked',true);
					break;
				default:
					e.val(product[i]);				
			}
		}
		
        for(var i in product.info){
            var info = product.info[i];
			for(var j in info){
				$('.form-horizontal [name="info['+info.lang_id+']['+j+']"]"').val(info[j]);
			}
        }
        for(var i in product.catalogues){
            var cat_id = product.catalogues[i].cat_id;
            $('.form-horizontal [name="catalogues[]"][value="'+cat_id+'"]').attr('checked',true);
        }
        for(var i in product.locations){
            var location_id = product.locations[i].location_id;
            $('.form-horizontal [name="locations[]"][value="'+location_id+'"]').attr('checked',true);
        }
        var img_gallery = '';
        for(var i in product.images)
        {
            var img=product.images[i];
            img_gallery+='<li>'+
				'<img src="'+img.thumb+'" alt="placeholder">'+
				'<div>'+
				'<ul style="width:67px">'+
				'<li class="edit"><a href="'+img.path+'"><?= lang('view') ?></a></li>'+
				'<li class="delete" data="'+img.id+'"><a href="#"><?= lang('delete') ?></a></li>'+
				'</ul>'+
				'</div>'+
				'</li>';
        }
        $('#basicGallery').html(img_gallery);
        var errors = <?= json_encode($errors) ?>;
        for(var i in errors)
        {
            if(i=='id' || i=='catalogues' || i=='locations')
            {
				$('.form-horizontal').children(':first').before('<div class="alert alert-error">'+
                        '<button data-dismiss="alert" class="close" type="button">×</button>'+
                        errors[i]+
                      '</div>');
				$('.form-horizontal').find('p').css({margin: 0});
            }
            else if(errors[i]!=''){
                $('.form-horizontal [name="'+i+'"]').after('<span class="help-inline">'+errors[i]+'</span>');
                $('.form-horizontal [name="'+i+'"]').parent().parent().addClass('error');
            }
        }*/

    });
</script>
